package casa.depesos.app.com.dlg;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import casa.depesos.app.com.activity.WebActivity;
import casa.depesos.app.com.databinding.DlgUpdateBinding;


public class UpdateDlg extends FullScreenDlg {

    DlgUpdateBinding binding;
    boolean force;
    String url;
    int from;

    public UpdateDlg setParam(boolean force, String url, int from) {
        this.from = from;
        this.force = force;
        this.url = url;
        return this;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DlgUpdateBinding.inflate(inflater, container, false);
        if (force) {
            setCancelable(false);
            binding.cancel.setVisibility(View.GONE);
        } else {
            binding.cancel.setOnClickListener(view -> dismiss());
        }
        if (from == 1) {
            binding.ok.setText("Actualizar ahora");
            binding.cancel.setText("No actualizar por el momento");
        }
        binding.ok.setOnClickListener(view -> {
            WebActivity.startGooglePlay(url);
            if (!force) {
                dismiss();
            }
        });
        return binding.getRoot();
    }
}
